package controller

import (
	"AutoPacConfig/src/config"
	"AutoPacConfig/src/middleware"
	"github.com/gin-gonic/gin"
	"net/http"
)

// GetProxyDomain 获取代理域名
func (c *Controller) GetProxyDomain(ctx *gin.Context) {
	//var result []dto.ProxyDomain
	var result []map[string]any

	//SELECT  id,match_tail_domain,cid,is_match_domain_suffix  FROM proxy_domain  where cid in (5,4,3) AND deleted_at is NULL AND is_match_domain_suffix=1;
	res := config.Gdb.Table("proxy_domain").
		Select("id,match_tail_domain,cid").
		Where("cid  in  (?)", config.Gdb.
			Table("proxy_domain_category").
			Select("id").
			Where("is_enable=1")).
		Where("deleted_at is NULL AND is_match_domain_suffix=1").
		Find(&result)

	if res.Error != nil {
		middleware.Fail(ctx, http.StatusInternalServerError, "获取代理域名失败", "")
		return
	}
	if res.RowsAffected == 0 {
		middleware.Success(ctx, http.StatusOK, "暂无代理域名记录.", "")
	} else {
		middleware.Success(ctx, http.StatusOK, "获取代理域名列表成功.", result)
	}
}

func (c *Controller) Get(ctx *gin.Context) {

}
